package cn.xinzhi.service.impl;

import cn.xinzhi.dao.IUserInfoDao;
import cn.xinzhi.service.IPageService;
import cn.xinzhi.until.MyBatisUtil;
import cn.xinzhi.until.PageUtil;

public class PageServiceImpl implements IPageService {

    @Override
    public PageUtil showPage(String index, String pageSize) {
        PageUtil pu = new PageUtil();
        IUserInfoDao mapper = MyBatisUtil.getSqlSession().getMapper(IUserInfoDao.class);
        pu.setTotalCount(mapper.getCount());//总记录数
        if(pageSize != null){
            pu.setPageSize(Integer.parseInt(pageSize));
        }//每页显示条目数
        if(index != null){
            int indexNum = Integer.parseInt(index);
            if(indexNum<1){
                indexNum = 1;
            }else if (indexNum>pu.getPageTotalCount()){
                indexNum = pu.getPageTotalCount();
            }
            pu.setIndex(indexNum);
        }//当前页码
        pu.setUis(mapper.getPage((pu.getIndex()-1)*pu.getPageSize(),pu.getPageSize()));//当页信息
        return pu;
    }
}
